@echo off
:: Set libzmq path
set LIBZMQ_PATH=libs\libzmq-master

:: Check and delete the existing build folder
if exist "%LIBZMQ_PATH%\build" (
    rd /s /q "%LIBZMQ_PATH%\build"
)

:: Check if the CMakeLists.txt file exists
if not exist "%LIBZMQ_PATH%\CMakeLists.txt" (
    echo ERROR: CMakeLists.txt file not found. Please ensure that libzmq is cloned correctly in %LIBZMQ_PATH%
    exit /b 1
)

:: Create and enter the build directory
mkdir "%LIBZMQ_PATH%\build"
cd "%LIBZMQ_PATH%\build"

:: Configure CMake with MinGW compiler
cmake -G "MinGW Makefiles" ..

:: Check if CMake configuration was successful
if %errorlevel% neq 0 (
    echo CMake configuration failed
    exit /b 1
)

:: Compile the project with MinGW
mingw32-make

:: Check if compilation was successful
if %errorlevel% equ 0 (
    echo libzmq compilation successful
) else (
    echo libzmq compilation failed
    exit /b 1
)

:: Return to the original directory
cd ..\..\..
